// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueI18n from 'vue-i18n'
//引入Element的语言包
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'


Vue.use(VueI18n)
Vue.config.productionTip = false

const i18n = new VueI18n({
	locale: localStorage.lang || 'cn',
	messages: {
		'cn': Object.assign(require('./i18n/langs/cn.json'), zhLocale),
		'en': Object.assign(require('./i18n/langs/en.json'), enLocale), //将我们项目中的语言包与Element的语言包进行合并
	},
});
Vue.use(ElementUI, {
	i18n: (key, value) => i18n.t(key, value)
});
/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	i18n,
	components: {
		App
	},
	template: '<App/>'
})
////////面包屑导航
var routeList = [];
router.beforeEach((to, from, next) => {
	var index = -1;
	for(var i = 0; i < routeList.length; i++) {
		if(routeList[i].name == to.name) {
			index = i;
			break;
		}
	}
	if(index !== -1) {
		//如果存在路由列表，则把之后的路由都删掉
		routeList.splice(index + 1, routeList.length - index - 1);
	} else if(to.name != 'login') {
		routeList.push({
			"name": to.name,
			"path": to.fullPath
		});
	}
	to.meta.routeList = routeList;
	next()
});
